import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2021/12/10 16:17
 * @description 时间复杂度不好，需要优化。
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.getRow(4);
    }

    public List<Integer> getRow(int rowIndex) {
        List<Integer> ans = new ArrayList<>();
        ans.add(1);
        for (int i = 0; i <= rowIndex; i++) {
            List<Integer> temp = new ArrayList<>(ans);
            ans.clear();
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    ans.add(1);
                }else {
                    ans.add(temp.get(j-1) + temp.get(j));
                }
            }
        }
        return ans;
    }
}
